
<% layout('/layouts/default.html', {title: '车站调度确认倒车通知单', libs: ['dataGrid']}){ %>
<div class="main-content">
	<div class="box box-main">
		<div class="box-header">
			<div class="box-title">

				<i class="fa icon-notebook"></i> ${text('车站调度确认倒车通知单')}
			</div>
			<div class="box-tools pull-right">
				<a href="#" class="btn btn-default" id="btnSearch" title="${text('查询')}"><i class="fa fa-filter"></i> ${text('查询')}</a>
				<a href="#" class="btn btn-default" id="btnSetting" title="${text('设置')}"><i class="fa fa-navicon"></i></a>
			</div>
		</div>
		<div class="box-body">
			<#form:form id="searchForm" model="${tblXdZxxdctzd}" action="${ctx}/tbl/lineform/tblXdZxxdctzd/listData2" method="post" class="form-inline"
					data-page-no="${parameter.pageNo}" data-page-size="${parameter.pageSize}" data-order-by="${parameter.orderBy}">
				<div class="form-group">
					<label class="control-label">${text('班别')}：</label>
					<div class="control-inline width-120">
						<#form:select path="remark" dictType="shift_type" blankOption="true" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('日期')}：</label>
					<div class="control-inline">
						<#form:input path="addTime" readonly="true" maxlength="20" class="form-control laydate"
							dataFormat="date" data-type="date" data-format="yyyy-MM-dd" />
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('车站')}：</label>
					<div class="control-inline width-120">
						<#form:select path="dqczbh" maxlength="2" items="${lineList}" itemLabel="stationName" itemValue="stationCode" class="form-control" onchange="stationChange()"/>
					</div>
				</div>
				<div class="form-group">
					<label class="control-label">${text('导出线路')}：</label>
					<div class="control-inline width-120">
						<#form:select path="dqxlbh" maxlength="10" items="${lineListByStation}" itemLabel="line" itemValue="lineCode" class="form-control"  />
					</div>
				</div>
				<div class="form-group">
					<div class="control-inline">
						<#form:checkbox path="deviceNo" dictType="all_line" class="form-control"/>
					</div>
				</div>
				<div class="form-group">
					<button type="submit" class="btn btn-primary btn-sm">${text('查询')}</button>
					<button type="reset" class="btn btn-default btn-sm">${text('重置')}</button>
					<button onclick="confirmBtn()" class="btn btn-primary btn-sm">${text('确认')}</button>
					<button onclick="cancelBtn()" class="btn btn-primary btn-sm">${text('撤销')}</button>
				</div>
			</#form:form>
			<table id="dataGrid"></table>
			<div id="dataGridPage"></div>
		</div>
	</div>
</div>
<% } %>
<script>
	$(function(){
		// 定义一个函数来更新班次和日期
		function updateShiftAndTime() {
			var $shift = $("#shift");
			var date_now = new Date();


			var hours = date_now.getHours();
			var year = date_now.getFullYear();  // 获取年
			var month = date_now.getMonth() + 1;  // 获取月
			var day = date_now.getDate();  // 获取日
			var $stationTime = $("#stationTime");
			console.log(hours);
			// 设置班次和日期
			if (hours >= 8 && hours < 19) {
				$shift.val('2').trigger('change'); // 白班
			} else {
				$shift.val('1').trigger('change'); // 夜班
			}

			// 设置日期，补零处理
			$stationTime.val(year + "-" + (month < 10 ? '0' + month : month) + "-" + (day < 10 ? '0' + day : day));
		}

		// 页面加载时更新一次
		updateShiftAndTime();

		// 每隔一分钟更新一次班次和日期
		// setInterval(updateShiftAndTime, 60000);
	});
// 初始化DataGrid对象
$('#dataGrid').dataGrid({
	searchForm: $("#searchForm"),
	multiselect:true,
	rownumWidth:40,
	shrinkToFit:false,
	columnModel: [
		{header:'${text("操作")}', name:'actions', width:120, formatter: function(val, obj, row, act){
			var actions = [];
			if("0" == row.status) {
				actions.push('<a href="${ctx}/tbl/lineform/tblXdZxxdctzd/form?recId='+row.recId+'" class="btnList" title="${text("编辑站修线倒车通知单")}"><i class="fa fa-pencil"></i></a>&nbsp;');
				
				return actions.join('');
			}else{
				return actions.join('');
			}
		}},
		{header:'${text("车号")}', name:'wagonno', index:'a.wagonno', width:150, align:"center", frozen:true, formatter: function(val, obj, row, act){
			return '<a href="${ctx}/tbl/lineform/tblXdZxxdctzd/form?recId='+row.recId+'" class="btnList" data-title="${text("编辑站修线倒车通知单")}">'+(val||row.id)+'</a>';
		}},
		{header:'${text("设备号")}', name:'deviceNo', index:'a.device_no', width:150, align:"center"},
		{header:'${text("当前车站名称")}', name:'dqczmc', index:'a.dqczmc', width:150, align:"center"},
		{header:'${text("当前场地名称")}', name:'dqcdmc', index:'a.dqcdmc', width:150, align:"center"},
		{header:'${text("当前线路名称")}', name:'dqxlmc', index:'a.dqxlmc', width:150, align:"center"},
		{header:'${text("车组名称")}', name:'wagonGroupName', index:'a.wagon_group_name', width:150, align:"center"},
		{header:'${text("是否出场")}', name:'isOutStage', index:'a.is_out_stage', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ZXZZ')}, val, '${text("未知")}', true);
		}},
		{header:'${text("去向")}', name:'destName', index:'a.dest_name', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('CLQX')}, val, '${text("未知")}', true);
		}},
		{header:'${text("是否禁峰")}', name:'isNopeak', index:'a.is_nopeak', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("未知")}', true);
		}},
		{header:'${text("出场状况")}', name:'cczk', index:'a.cczk', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('sys_yes_no')}, val, '${text("未知")}', true);
		}},
		{header:'${text("专项整治")}', name:'zxzz', index:'a.zxzz', width:150, align:"center", formatter: function(val, obj, row, act){
			return js.getDictLabel(${@DictUtils.getDictListJson('ZXZZ')}, val, '${text("未知")}', true);
		}},
		{header:'${text("备注")}', name:'remark', index:'a.remark', width:150, align:"center"}
	],
	// 加载成功后执行事件
	ajaxSuccess: function(data){
		
	}
}).dataGrid('setLabel', 'rn', '序号');

function stationChange(){
	var params={"stationCode":$("#dqczbh").val()};
	$.post("${ctx}/tbl/replyform/tblXdJxchsd/getLineList",params,function(data){
console.log(data);
		var lineCode = $("#dqxlbh")[0];  //清空原来下拉框的值
		lineCode.options.length = 0;

		//进行循环判断并追加数据到二级下拉框中
		for (var i of data) {
			lineCode.options.add(new Option(i.line, i.lineCode));  //往下拉框中追加值
		}
		
	},"json");
}

function delBtn(){
	var ids = $("#dataGrid").jqGrid("getGridParam", "selarrrow");
	if(ids.length==0){
		js.showMessage('请选择要删除的记录。', '', 'warning', 4000);
		return;
	}else{
		var msg = "确定进行【删除】操作？"; 
		js.confirm(msg,function(data){
			var jhhString = "";//拼接字符串 
			for(var i=0;i<ids.length;i++){
				jhhString += ","+ids[i];
			}
			console.log(jhhString);
			if(""!=jhhString) {
				jhhString=jhhString.substring(1);
			}
			console.log(jhhString);
		    $.post("${ctx}/tbl/lineform/tblXdZxxdctzd/delete",{'jhhString':jhhString},function(e){
		    	$('#dataGrid').trigger("reloadGrid");
		    },"json");
		});
	}
}

//新增
function addBtn(){
	var exportLine = $("#dqxlbh").val();
	if(exportLine == ""){
		js.showMessage('请选择导出线路！', '', 'warning', 4000);
		return;
	}
	$.post("${ctx}/tbl/lineform/tblXdZxxdctzd/insertData",{'dqxlbh':exportLine},function(e){},"json");
}
</script>